import { createVNode, render } from 'vue'
import Message from './Message'
import confirm from './xtx-confirm.vue'

const boxV = createVNode('div', { class: 'xtx-containner-confirm' })
render(boxV, document.body)
console.log(boxV.el)
const div = boxV.el

export default ({ title, text }) => {
  return new Promise((resolve, reject) => {
    const cancelCallback = () => {
      render(null, div)
      Message({ type: 'warn', msg: '点击取消' })
      reject(new Error('点击取消'))
    }
    const confirmCallback = () => {
      render(null, div)
      resolve()
    }

    const confirmCop = createVNode(confirm, {
      title,
      text,
      confirmCallback,
      cancelCallback,
    })

    render(confirmCop, div)
  })
}
